package com.naraba.socket.protocol;

import com.alibaba.fastjson.JSON;

/**
 * @auther xjl
 * @date 2020/10/30
 * @description 实现上面定义的序列化接口
 **/
public class JSONSerializer implements  Serializer{
    @Override
    public byte getSerializerAlogrithm() {
      //获取上面的序列化标识
        return SerializerAlgorithm.JSON;
    }

    @Override
    public byte[] serialize(Object object) {
        return JSON.toJSONBytes(object);
    }

    @Override
    public <T> T deserialize(Class<T> clazz, byte[] bytes) {
        return JSON.parseObject(bytes, clazz);
    }
}
